import java.util.ArrayList;
import java.util.List;

public class Solution155 {

    List<Integer> origin;
    List<Integer> max;

    public Solution155() {
        origin=new ArrayList<>();
        max=new ArrayList<>();
    }

    public void push(int val) {
        origin.add(val);
        if (max.isEmpty()||val<origin.get(max.get(max.size()-1))){
            max.add(origin.size()-1);
        }
    }

    public void pop() {
        if (!max.isEmpty()&&max.get(max.size()-1)==origin.size()-1){
            max.remove(max.size()-1);
        }
        origin.remove(origin.size()-1);
    }

    public int top() {
        return origin.get(origin.size()-1);
    }

    public int getMin() {
        return origin.get(max.get(max.size()-1));
    }

    public static void main(String[] args) {
        Solution155 solution155=new Solution155();
        solution155.push(-2);
        solution155.push(0);
        solution155.push(-3);
        System.out.println(solution155.getMin());
        solution155.pop();
        System.out.println(solution155.top());
        System.out.println(solution155.getMin());
    }
}
